package com.uwo.house.controller;

import com.uwo.house.service.serviceImpl.RoleService;
import com.uwo.house.util.UtilReturn;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by yanhao on 2017/7/19.
 */
@Controller
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @RequiresPermissions("role:init")
    @RequestMapping(value = {"", "/"})
    @ResponseBody
    public Object init(){
        return "init";
    }

    @RequiresPermissions("role:save")
    @RequestMapping(value = "/save")
    @ResponseBody
    public Object save(){
        return "save";
    }

    @RequiresPermissions("role:modify")
    @RequestMapping(value = "/modify")
    @ResponseBody
    public Object modify(){
        return "modify";
    }

    @RequiresPermissions("role:remove")
    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
    @ResponseBody
    public Object remove(@PathVariable Long id){
        int count = roleService.remvoe(id);
        if(count > 0)
            return UtilReturn.resSuccesssMap(UtilReturn.SUCCESS_STATUS, UtilReturn.SUCCESS_CODE, null);
        return UtilReturn.resErrorMap(UtilReturn.ERROR_STATUS, UtilReturn.ERROR_CODE);
    }

    @RequiresPermissions("role:user")
    @RequestMapping(value = "/user")
    @ResponseBody
    public Object user(){
        return "user";
    }

}
